package com.app.backend.filter;

import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @program: AccessFilter
 * @description: 允许跨域
 * @author: Zhun.Xiao
 * @create: 2018-10-29 11:26
 **/
public class AccessFilter extends OncePerRequestFilter {

    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
        //设置允许跨域
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Methods", "POST, GET");
        //允许content-type跨域
        response.setHeader("Access-Control-Allow-Headers", "x-requested-with,content-type,access-token,user-view-object");
        filterChain.doFilter(request, response);
    }
}
